﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;

namespace HandMade_Q4T_
{
    public class C_Comment
    {
        string id_comment, masp, comment, tenkh, email;
        bool thich, duyet;
        C_XLDL db = new C_XLDL();
        #region Property
        public bool Duyet
        {
            get { return duyet; }
            set { duyet = value; }
        }

        public bool Thich
        {
            get { return thich; }
            set { thich = value; }
        }

        public string Email
        {
            get { return email; }
            set { email = value; }
        }

        public string Tenkh
        {
            get { return tenkh; }
            set { tenkh = value; }
        }

        public string Comment
        {
            get { return comment; }
            set { comment = value; }
        }

        public string Masp
        {
            get { return masp; }
            set { masp = value; }
        }

        public string Id_comment
        {
            get { return id_comment; }
            set { id_comment = value; }
        }
        #endregion

        #region Constructor
        public C_Comment()
        { }
        #endregion

        #region Xử lí
        /// <summary>
        /// Lấy tất cả comment đã được admin check
        /// </summary>
        /// <param name="sql">câu truy vấn</param>
        /// <returns>Danh sách comment</returns>
        public List<C_Comment> Get_Comment_checked(string sql)
        {
            DataTable dt = db.BangDuLieu(sql);
            List<C_Comment> list = new List<C_Comment>();
            Set_array_comment(list, dt);
            return list;
        }

        public void Set_array_comment(List<C_Comment> list,DataTable dt)
        {            
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                C_Comment cm = new C_Comment();
                cm.Id_comment = dt.Rows[i][0].ToString();
                cm.Masp = dt.Rows[i][1].ToString();
                cm.Comment = dt.Rows[i][2].ToString();
                cm.Thich = bool.Parse(dt.Rows[i][3].ToString());
                cm.Tenkh = dt.Rows[i][4].ToString();
                cm.Email = dt.Rows[i][5].ToString();
                cm.Duyet = bool.Parse(dt.Rows[i][6].ToString());
                list.Add(cm);
            }
        }

        public bool Update_Comment(string sql)
        {
            try
            {
                db.ThucHienLenh(sql);
                return true;
            }
            catch
            {
                return false;
            }

        }
        #endregion

    }
}